home *** CD-ROM | disk | FTP | other *** search
/ Amiga Collections: Topik / Topik - Disk 02 - Fonts and CLI Commands (19xx)(Topik Public Domain)(PD)[a][WB].zip / Topik - Disk 02 - Fonts and CLI Commands (19xx)(Topik Public Domain)(PD)[a][WB].adf / Source / speed.c < prev    next >
C/C++ Source or Header  |  1989-04-20  |  3KB  |  145 lines

  1. #include <stdio.h>
  2. #include <libraries/dos.h>
  3. #include <exec/memory.h>
  4. #include <exec/exec.h>
  5. #include "libraries/dos.h"        /* for requestor turn-off */
  6. #include "libraries/dosextens.h"/* for requestor turn-off */
  7. char * AllocMem();
  8. struct Process *FindTask();
  9. long    Read();
  10. long    Write();
  11. APTR    save_WindowPtr = (APTR) NULL;    
  12.                 /* Place to save the process' pr_WindowPtr while
  13.                     we disable "requestors" */
  14.  
  15. /*
  16. Function    requestors_off
  17.  
  18. Description: 
  19.     Make sure that "requestors" (boxes in the upper left hand corner of the
  20.     screen) don't appear.
  21.  
  22. Inputs:
  23.     None.
  24.  
  25. Outputs:
  26.     None.
  27.  
  28. Global variables used:
  29.     Saves the old value of the process' pr_WindowPtr in save_WindowPtr.
  30.  
  31. */
  32. void requestors_off()
  33. {
  34.     struct Process *o_proc;
  35.  
  36.     o_proc = (struct Process *) FindTask (NULL);
  37.     save_WindowPtr = o_proc->pr_WindowPtr;
  38.     o_proc->pr_WindowPtr = -1L;
  39. }
  40.  
  41. /*
  42. Function    requestors_restore
  43.  
  44. Description: 
  45.     Restores the process' pr_WindowPtr to whatever it was to begin with.
  46.  
  47. Inputs:
  48.     None.
  49.  
  50. Outputs:
  51.     None.
  52.  
  53. Global variables used:
  54.     Gets the old value of the process' pr_WindowPtr from save_WindowPtr.
  55.  
  56. */
  57. void requestors_restore()
  58. {
  59.     struct Process *o_proc;
  60.  
  61.     o_proc = (struct Process *) FindTask (NULL);
  62.     o_proc->pr_WindowPtr = save_WindowPtr;
  63. }
  64. long millisec()
  65. {
  66.     /* Returns time in milliseconds since midnite. Changed every 50 ms. */
  67.     long DateStamp();
  68.     long    v[3];
  69.  
  70.     DateStamp(v);
  71.     return ( (v[1] * 60000L) + (v[2] * 20L));
  72. }
  73. void main()
  74. {
  75. long f;
  76. char *buff;
  77. long time1, time2, i, iter, size;
  78. long x1, x2;
  79. double ksec;
  80. char s[100];
  81.  
  82.     requestors_off();
  83.   printf("Enter block size in Kbytes->"); /* get buffer size for io */
  84.   gets(s);
  85.   sscanf(s,"%ld\n", &size);
  86.   size = size * 1024;
  87.   printf("Enter number of iterations ->"); /* get number of iterations */
  88.   gets(s);
  89.   sscanf(s,"%ld\n", &iter);                   /* to use buffer per operation */
  90.   printf("Block size, interations = %ld, %ld\n", size, iter);
  91.   buff = (char *)AllocMem(size, MEMF_CLEAR);
  92.   if (buff == 0) {              /* alloc failed so exit */
  93.     printf("Not enough contigious memory; block size = %ld\n", size);
  94.     exit();
  95.   }
  96.  
  97.   f = Open("test.file", MODE_NEWFILE);
  98.  
  99.  Forbid();
  100.  x1 = millisec();
  101.     for (i = 0; i < iter; i++)
  102.     {
  103.         if (Write(f, buff, size) < size)
  104.         {
  105.             printf ("Write failed on attempt %d\n", i);
  106.             break;
  107.         }
  108.     }
  109.     x2 = millisec();
  110.     Permit();
  111.  
  112. /* the getclk call returns an char array[8], where array[5] is minutes,
  113.    array[6] is seconds, and array[7] is hundredths of seconds */
  114.   ksec = (double)(((double)(size * iter) / (double)(x2 - x1))
  115.     * 1000.0) / 1024.0; /* convert elapsed time to k/second */
  116.   printf("elapsed time for write = %ld millisec., K/sec = %10.4f\n",
  117.      (x2 - x1), ksec);
  118.   Close(f);
  119.  
  120.   Delay(10L);  /* give file system time to settle before next test */
  121.                /* didn't know if I needed this, but just in case */
  122.  
  123.   f = Open("test.file", MODE_OLDFILE);
  124.  
  125.  x1 = millisec();
  126.   for (i = 0; i < iter; i++)
  127.     {
  128.         if (Read(f, buff, size) < size)
  129.         {
  130.             printf ("Read failed on attempt %d\n", i);
  131.             break;
  132.         }
  133.     }
  134.  x2 = millisec();
  135.  
  136.   ksec = (double)(((double)(size * iter) / (double)(x2 - x1))
  137.     * 1000.0) / 1024.0;  /* convert elapsed time to k/second */
  138.   printf("elapsed time for read = %ld millisec., K/sec = %10.4f\n",
  139.      (x2 - x1), ksec);
  140.   Close(f);
  141.   DeleteFile("test.file");  /* get rid of the temp file */
  142.   FreeMem(buff, size);
  143.   requestors_restore();
  144. }
  145.